package com.ruoyi.web.controller.system;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.system.domain.Nurse;
import com.ruoyi.system.domain.OldMan;
import com.ruoyi.system.service.INurseService;
import com.ruoyi.system.service.IOldManService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CareLog;
import com.ruoyi.system.service.ICareLogService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 护理日志Controller
 *
 * @author 王帅
 * @date 2024-11-03
 */
@Controller
@RequestMapping("/system/log")
public class CareLogController extends BaseController {
    private String prefix = "system/log";
    @Autowired
    private IOldManService oldManService;
    @Autowired
    private ICareLogService careLogService;
    @Autowired
    private INurseService nurseService;


    @GetMapping()
    public String log() {
        return prefix + "/log";
    }

    /**
     * 查询护理日志列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CareLog careLog) {
        startPage();
        List<CareLog> list = careLogService.selectCareLogList(careLog);
        return getDataTable(list);
    }

    /**
     * 导出护理日志列表
     */
    @RequiresPermissions("system:log:export")
    @Log(title = "护理日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CareLog careLog) {
        List<CareLog> list = careLogService.selectCareLogList(careLog);
        ExcelUtil<CareLog> util = new ExcelUtil<CareLog>(CareLog.class);
        return util.exportExcel(list, "护理日志数据");
    }

    /**
     * 新增护理日志
     */
    @GetMapping("/add")
    public String add(ModelMap mmap) {
        List<OldMan> oldMEN = oldManService.selectOldManList(new OldMan());
        mmap.put("olds", oldMEN);
        List<String> careTypes = new ArrayList<>();
        careTypes.add("医疗");
        careTypes.add("日常护理");
        careTypes.add("康复");
        mmap.put("careTypes", careTypes);
        List<Nurse> nurses = nurseService.selectNurseList(new Nurse());
        mmap.put("nurses", nurses);
        return prefix + "/add";
    }

    /**
     * 新增保存护理日志
     */
    @Log(title = "护理日志", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CareLog careLog) {
        return toAjax(careLogService.insertCareLog(careLog));
    }

    /**
     * 修改护理日志
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        CareLog careLog = careLogService.selectCareLogById(id);
        List<OldMan> oldMEN = oldManService.selectOldManList(new OldMan());
        mmap.put("olds", oldMEN);
        mmap.put("careLog", careLog);
        List<String> careTypes = new ArrayList<>();
        careTypes.add("医疗");
        careTypes.add("日常护理");
        careTypes.add("康复");
        mmap.put("careTypes", careTypes);
        List<Nurse> nurses = nurseService.selectNurseList(new Nurse());
        mmap.put("nurses", nurses);
        return prefix + "/edit";
    }

    /**
     * 修改保存护理日志
     */
    @Log(title = "护理日志", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CareLog careLog, ModelMap mmap) {
        List<OldMan> oldMEN = oldManService.selectOldManList(new OldMan());
        mmap.put("olds", oldMEN);

        mmap.put("olds", oldMEN);

        List<Nurse> nurses = nurseService.selectNurseList(new Nurse());
        mmap.put("nurses", nurses);
        return toAjax(careLogService.updateCareLog(careLog));
    }

    /**
     * 删除护理日志
     */
    @Log(title = "护理日志", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(careLogService.deleteCareLogByIds(ids));
    }
}
